/**
 * 
 */
package org.gbif.crawler.ws.mock;

import org.gbif.api.model.common.paging.PagingResponse;
import org.gbif.api.model.metrics.DatasetCrawlMetrics;
import org.gbif.api.model.metrics.RecordError;
import org.gbif.api.service.crawler.CrawlerDetailService;

import java.util.List;
import java.util.UUID;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;

@Deprecated
public class MockCrawlerDetailService implements CrawlerDetailService {

  private static final int RUNNING_SIZE = 15000;
  private static final int QUEUE_SIZE = 10;

  private static final List<UUID> running;
  private static final List<UUID> queued;

  static {


    ImmutableList.Builder<UUID> b = ImmutableList.builder();
    for (int i = 0; i < RUNNING_SIZE; i++) {
      b.add(UUID.randomUUID());
    }
    running = b.build();
    b = ImmutableList.builder();
    for (int i = 0; i < QUEUE_SIZE; i++) {
      b.add(UUID.randomUUID());
    }
    queued = b.build();
  }

  @Override
  public PagingResponse<RecordError> getDatasetDetailedErrors(UUID key) {
    throw new UnsupportedOperationException();
  }

  @Override
  public DatasetCrawlMetrics getCrawlMetrics(UUID key) {
    return mock().apply(key);
  }

  @Override
  public List<DatasetCrawlMetrics> getCrawlMetricsList() {
    return ImmutableList.copyOf(Iterables.transform(running, mock()));
  }

  // Decorator function creating a mock dataset crawl metrics from the key
  private static Function<UUID, DatasetCrawlMetrics> mock() {
    return new Function<UUID, DatasetCrawlMetrics>() {

      @Override
      public DatasetCrawlMetrics apply(UUID key) {
        return DatasetCrawlMetrics.builder().datasetKey(key).crawlContext("Tim").build();
      }
    };
  }

  @Override
  public List<UUID> getRunningCrawls() {
    return running;
  }

  @Override
  public List<UUID> getQueuedCrawls() {
    return queued;
  }
}
